package com.bcxk.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bcxk.constants.Constants;
import com.bcxk.entity.dto.Order;
import com.bcxk.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * @author NieMingkun
 */

@Service
public class OrderService extends ServiceImpl<OrderMapper , Order> {
    @Autowired
    OrderMapper orderMappers;

     //查询订单 根据商户id 预定时间 订单状态 手机号码 订单号 用户名
    public IPage<Order> getOrderByCreateTime(Long merchantId,int pageNum ,
                                     String startTime ,String endTime ,String text ,Long payState  ){
        Page<Order> page = new Page<>(pageNum,Constants.ORDER_LEN);
       return orderMappers.getOrderByReTime(page,merchantId,startTime,endTime,text,payState);
    }
    //查询订单 根据商户id 离店时间 订单状态 手机号码 订单号 用户名
    public IPage<Order> getOrderByOutTime(Long merchantId,int pageNum ,
                                            String startTime ,String endTime ,String text ,Long payState  ){
        Page<Order> page = new Page<>(pageNum,Constants.ORDER_LEN);
        return orderMappers.getOrderByOutTime(page,merchantId,startTime,endTime,text,payState);
    }

    //查询订单 根据商户id 入住时间 订单状态 手机号码 订单号 用户名
    public IPage<Order> getOrderByInTime(Long merchantId,int pageNum ,
                                            String startTime ,String endTime ,String text ,Long payState  ){
        Page<Order> page = new Page<>(pageNum,Constants.ORDER_LEN);
        return orderMappers.getOrderByInTime(page,merchantId,startTime,endTime,text,payState);
    }

    //查询订单 根据商户
    public IPage getOrderByMerchant(Long merchantId,int pageNum  ){
        Page<Order> page = new Page<>(pageNum,Constants.ORDER_LEN);
        QueryWrapper<Order> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Order::getMerchantId,merchantId)
                .orderByAsc(Order::getCreatTime);
        return this.page(page,wrapper);
    }


    public void orderUpdate(String orderNo, long state) {
        this.baseMapper.orderUpdate(orderNo,state);
    }

    //根据id修改订单状态
    public void orderUpdate(String orderNos) {
        this.baseMapper.updateOrderByOrderNos(orderNos);
    }
}
